//
//  MLUserAccount.swift
//  MLWeiBo
//
//  Created by wenxing on 2017/1/7.
//  Copyright © 2017年 Se7venX. All rights reserved.
//

import UIKit

class MLUserAccount: NSObject,NSCoding {
    
    // 令牌
    var access_token:String?
    
    // 有效周期
    var expires_in:Double = 0 {
    
        didSet{
        
            expires_date = Date(timeIntervalSinceNow: expires_in )
        }
    }
    
    // 过期date
    var expires_date:Date?
    
    //uid
    var uid:String?
    
    //名称
    var name:String?
    
    //头像
    var avatar_large:String?
    
    //MARK:- 字典转模型 -
    init(dic:[String:Any]) {
        super.init()
        
        setValuesForKeys(dic)
    }
    
    
    override func setValue(_ value: Any?, forUndefinedKey key: String) {
        
    }
    
    //MARK:- 函数 -
    required init?(coder aDecoder: NSCoder) {
    
        access_token = aDecoder.decodeObject(forKey: "access_token") as? String
//        expires_in = aDecoder.decodeObject(forKey: "expires_in") as! Double
        expires_date = aDecoder.decodeObject(forKey: "expires_date") as? Date
        uid = aDecoder.decodeObject(forKey: "uid") as? String
        
        name = aDecoder.decodeObject(forKey: "name") as? String

        avatar_large = aDecoder.decodeObject(forKey: "avatar_large") as? String

    }
    
    
    func encode(with aCoder: NSCoder) {
    
         aCoder.encode(access_token, forKey: "access_token")
//         aCoder.encode(expires_in, forKey: "expires_in")
         aCoder.encode(expires_date, forKey: "expires_date")
         aCoder.encode(uid, forKey: "uid")
        aCoder.encode(name, forKey: "name")
        aCoder.encode(avatar_large, forKey: "avatar_large")


    }
    

}
